package controller;

import java.util.List;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import pojo.User;
import service.UserService;
import service.UserServiceManager;



@org.springframework.stereotype.Controller

public class Controller {
	private UserService us;
	public Controller(){
		us=UserServiceManager.getServiceImpl();
		
	}
	
	@ResponseBody
	@RequestMapping(value="/addUser",consumes="application/json")
	public boolean addUser(@RequestBody User u,Model model){
		 
		us.addUser(u);

		return true;
	}
	
	@ResponseBody
	@RequestMapping(value="/getUser",method=RequestMethod.POST)
	public List<User> getUsers(){
		List<User> list=us.getUsers();
		return list;
	}
	
	@ResponseBody
	@RequestMapping(value="/deletUser",method=RequestMethod.GET)
	public boolean deleteUser(String id){
		 
		us.deleteUser(id);
		return true;
	}
	
	@ResponseBody
	@RequestMapping(value="/updateUser",consumes="application/json",method=RequestMethod.POST)
	public boolean updateUser(@RequestBody User u){
		
		 String id=u.getId();
		 System.out.println(id);
		 us.deleteUser(id);
		 us.addUser(u);
		 return true;
		 
	}
	
     

}
